﻿using System;
using System.Collections.Generic;

namespace DBCUnit
{
	public class AssertionContext
	{

		#region Properties

		internal static AssertionContext Current { get; private set; }

		internal IList<Assertion> Assertions { get; private set; }

		#endregion

		#region Constructor

		private AssertionContext()
		{
			Assertions = new List<Assertion>();
		}

		#endregion

		#region Methods

		public void Assert(Assertion assertion)
		{
			Assertions.Add(assertion);
		}

		#endregion

		public static void Setup()
		{
			Current = new AssertionContext();
		}

		public static void VerifyAll()
		{
			foreach(Assertion assertion in Current.Assertions)
			{
				if (!assertion.IsSatisfied)
					throw new ApplicationException("Assertion Failed: " + assertion.ExpectedValue + " " + assertion.ComparisonType +
					                               " " + assertion.ActualValue);
			}
		}
	}
}
